<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			// // 获取URL 参数并生成 Object
			// // 输入：http://www.jiduauto.com?key=1&test=4#hehe
			// // 输出：{key: 1, test: 4}

			const URLSearchToObject = () => {
				let url = new URL('http://www.jiduauto.com?key=1&test=4#hehe')
				let o = {}
				url.searchParams.forEach((value, key) => {
					o[key] = +value //写+ {key: 1, test: 4}  不写+ {key: '1', test: '4'}
					// 用parseInt一样 为啥会影响到符号 这不是隐式类型转换嘛....
				})
				return o
			}
			console.log(URLSearchToObject()) //{key: 1, test: 4}

			// const url = new URL('http://www.jiduauto.com?key=1&test=4#hehe')
			// const searchParams = new URLSearchParams(url.search)
			// const params = Object.fromEntries(searchParams.entries())
			// console.log(params)
			// // {key: '1', test: '4'}
		</script>
	</body>
</html>
